import java.util.Scanner;
/*********************************************************************
 * Copyright (C) 2008 by Duncan A. Buell.  All rights reserved.
 * Class to handle a single phonebook-like record of
 * <code>String</code> data.
 * @author Duncan A. Buell
 * @version 1.00 2009-02-10
**/
public class Record
{
/*********************************************************************
 * Instance variables for the class.
**/
  private static final String DUMMYSTRING = "dummy";
  private static final int DUMMYINT = Integer.MIN_VALUE;
  private int number;    /** the class number               */
  private String name;   /** the last name                  */

/*********************************************************************
 * Constructor.
**/
  public Record()
  {
    this.setName(Record.DUMMYSTRING);
    this.setNumber(Record.DUMMYINT);
  } // public Record()

/*********************************************************************
 * Accessors and mutators.
**/
/*********************************************************************
 * Accessor for the <code>name</code>.
 * @return the value of <code>name</code>.
**/
  public String getName()
  {
    return this.name;
  } // public String getName()

/*********************************************************************
 * Mutator for the <code>name</code>.
 * @param what the value of <code>name</code> to be set.
**/
  public void setName(String what)
  {
    this.name = what;
  } // public void setName(String what)

/*********************************************************************
 * Accessor for the <code>number</code>.
 * @return the value of <code>number</code>.
**/
  public int getNumber()
  {
    return this.number;
  } // public int getNumber()

/*********************************************************************
 * Mutator for the <code>number</code>.
 * @return the value of <code>number</code>
**/
  public void setNumber(int what)
  {
    this.number = what;
  } // public void setNumber(int what)

/*********************************************************************
 * General methods.
**/
/*********************************************************************
 * Method to compare two <code>Record</code> instances.
 * This should return:
 *
 *   -1 if this.name < that.name (as String data)
 *   -1 if this.name equals that.name (as String data) AND
 *         this.number < that.number
 *
 *    0 if this.name equals that.name (as String data) AND
 *         this.number == that.number
 *
 *   +1 if this.name > that.name (as String data)
 *   +1 if this.name equals that.name (as String data) AND
 *         this.number > that.number
 *
 * @return -1, 0, or +1 according as the comparison goes.
**/
  public int compareTo(Record that){
	  
	
		    int returnValue;

		    returnValue = 0;

		    if(this.getName().compareTo(that.getName()) < 0)
		    {
		    	
		      returnValue = -1;

		    }
		    else if(this.getName().equals(that.getName())&& this.number<that.number){
		    	returnValue= -1;
		
		    }
		    else if(this.getName().compareTo(that.getName()) > 0)
		    {
	
		      returnValue = +1;
		     
		    }
		    else if(this.getName().equals(that.getName())&& this.number>that.number){
		    	returnValue=+1;
		    	
		    }
		    else
		    {
		      returnValue = 0;
		 
		    }

		    return returnValue;
	  

  } // public int compareTo(Record that)

/*********************************************************************
 * Method to read the <code>Record</code> from an input
 * <code>Scanner</code> file. Note that this is more or less hard
 * coded. Also that we don't bulletproof the input; among other
 * things we assume that partial records don't appear in the input.
 *
 * @param the <code>Scanner</code> from which to read.
 *
 * @return the <code>Scanner</code> from which to read.
**/
  public static Record readRecord(Scanner inFile)
  {
    int n;    /** local variable for input of the course number */
    String s; /** local variable for input of the string data   */
    Record newRecord = null; /** the value returned             */
    
    // no bulletproofing--if *any* data exists we assume that
    // an entire record exists and in the right order and format
    newRecord = new Record();
    if(inFile.hasNext())
    {
      s = inFile.next();
      newRecord.setName(s);

      n = inFile.nextInt();
      newRecord.setNumber(n);
    }

    return newRecord;
  } // public static Record readRecord(Scanner inFile)

/*********************************************************************
 * Method to convert a record to a <code>String</code>.
 *
 * @return the formatted <code>String</code> value of the record.
**/
  public String toString()
  {
    String s;
    s = String.format("%-10s %4d",
                 this.getName(),this.getNumber());
    return s;
  } // public String toString()

} // public class Record
